import java.util.*;

public class Main{
    public static String  transfrom(int a,int b){
        //a为0
        if(a==0){
            return "0";
        }
        //余数数组
        char[]arr={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
        StringBuffer s=new StringBuffer();
        //a>0
        if(a>0){
            //取余
            while(a>0){
                //从余数数组里取对应的余数
                char n=arr[a%b];
                //拼接
                s.append(n);
                //得到的余数继续相除取余
                a=a/b;
            }
            return s.reverse().toString();
        }else{
            //a<0 则转化为正数计算
            a=0-a;
            while(a>0){
                char n=arr[a%b];
                s.append(n);
                a=a/b;
            }
            //负数得到余数加上负号
            s.append('-');
            return s.reverse().toString();
        }
    }
    public static void main(String []args){
        Scanner sc=new Scanner(System.in);

        int a=sc.nextInt();int b=sc.nextInt();

        String  c=transfrom(a,b);

        System.out.println(c);

    }
}